<%@page import="Test.TestPaper"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%@page import="Test.TestPaperState"%>
<%@page import="Test.Course"%>
<%@page import="DBModule.*"%>
<%@page import="Servlet.Alert"%>
<%@page import="User.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选择试卷进行批改</title>
<link rel="stylesheet" href="css/default.css" type="text/css" />
</head>
<body>
<center><br/><br/>
<h1>选择试卷进行批改</h1><br/>
<%
	User teacher = (User)session.getAttribute("user");
	if (teacher == null || teacher.getType() != User.TEACHER){
		Alert.toAlert(response, request, "用户未登陆，或不是教师");
		return;
	}
	
	Course course = null;
	try{
		course = CourseTable.getCourse(Integer.parseInt(request.getParameter("course")));
	}
	catch (Exception e){
		Alert.toAlert(response, request, "未选择科目");		
		return;
	}
	
	try{
		Collection<TestPaperState> set = TestPaperManager.getAllTestPaperBrief(course, false);
		Iterator<TestPaperState> iter = set.iterator();
		
		out.print("<form action=\"correct.jsp\"><table border=\"1\">");
		out.print("<th>试卷号</th><th>课程</th><th>当前状态</th><th>总分</th><th>选择这份试卷</th>");

		while (iter.hasNext()){
			TestPaperState state = iter.next();
			out.print(String.format("<tr><td>%d</td><td>%s</td><td>%s</td><td>%d</td>",
					state.getId(),
					course.getName(),
					state.getStateName(),
					state.getScore()));
			out.print("<td><input type=\"radio\" name=\"paperID\" value=\"" + state.getId() +"\" /></td></tr>");
		}
		out.print("</table>");
		out.print("<input type=\"submit\" value=\"确定\">");
		out.print("</form>");
	}

	catch (Exception e){
		String msg = e.getMessage();
		e.printStackTrace();
		Alert.toAlert(response, request, msg == null ? "未知的内部错误" : msg);
		return;
	}
%>
</center>
</body>
</html>









